package OnlineExam.question;

import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
import java.io.*;
import java.util.*;
import org.apache.struts.action.*;
import org.hibernate.*;
import org.hibernate.cfg.Configuration;
import OnlineExam.configuration.*;
import static OnlineExam.configuration.Configure.*;
import OnlineExam.db.*;


/**
 *  Modifies a given question.
 */

public class ModifyQuestionAction extends Action
{

	/**
	 *  An Action servlet to modify a question .
	 */

	public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, 
					HttpServletResponse response) 
	{
			
		Question q = (Question) form;
		// reads the options and adds a separator 
		//
		String optionsString = Question.assembleOptions (q.getOptionsArr()); 
		q.setOptions (optionsString);
		if (q.getExplanation() == null)
				q.setExplanation("N.A");
		
		try
		{
			DBUtil.update(q);
			return (mapping.findForward("success"));
		}
		catch (DBException e)
		{
			System.out.println ("Exception " + e);
			return (mapping.findForward ("failure"));
		}
	} // end ActionForward
} //end ModifyQuestionAction
